home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #34 (Jul 88) / Basic source / Professor Mac Says… < prev    next >
Text File  |  1988-05-14  |  8KB  |  303 lines

  1. ! Professor Mac Says…
  2. ! By David Kelly
  3. ! ©MacTutor, 1988
  4. ! With special thanks to Milton Bradley Co.
  5. ! For their "Simon" Game
  6.  
  7. LIBRARY "Mactools*"               ! MacStuff Library
  8. LIBRARY "PictLib*"                ! PICTStuff Library
  9. DECLARE DEF MacGetFile$
  10. DIM notes(31)
  11. RANDOMIZE
  12. LET skilllevel=8                  ! Set up levels
  13. LET level=1
  14. SET BACKGROUND COLOR 10           !  Get a Background color
  15. OPEN #1:screen .25,.67,.165,.75   ! open a section of screen
  16. WINDOW #1                         ! and use it as a window
  17. SET WINDOW 0,1,0,1
  18. ASK SCREEN a,b,c,d
  19. CALL set_frame(a,b,c,d)
  20.  
  21. LET filename$="Prof Says.PICT"    ! Get the PICT resource
  22. IF filename$<>"" THEN
  23.    CALL Read_pictfile(filename$,s$)
  24.    CALL Draw_string(s$,1)
  25. ELSE
  26.    PRINT "Prof Says.PICT file not found!"
  27. END IF
  28.  
  29. ! Set up the main screen
  30. CALL SetRed
  31. FLOOD .3,.7                       ! Fill the shape with Red
  32. CALL SetBlue
  33. FLOOD .7,.7                       ! Fill the shape with Blue
  34. CALL SetGreen
  35. FLOOD .3,.3                       ! Fill the shape with Green
  36. CALL SetYellow
  37. FLOOD .7,.3                       ! Fill the shape with Yellow
  38. ! Turn off all shapes
  39. CALL darkred
  40. CALL darkblue
  41. CALL darkgreen
  42. CALL darkyellow
  43. ASK WINDOW a,b,c,d
  44. BOX KEEP a,b,c,d in None$         ! Save PICT so it can be restored later
  45. CALL MacTextFont(2)               ! Get New York font
  46. SET TEXT JUSTIFY "center","half"
  47. DO                                ! Start the Main program loop
  48.    SET COLOR MIX (0) rnd,rnd,rnd  ! change the background color
  49.    CALL SetButtons(level)
  50.    DO
  51.       LET Animationcount=Animationcount+1
  52.       IF Animationcount>=500 then
  53.          SET COLOR MIX (0) rnd,rnd,rnd      ! change the background color
  54.          LET Animationcount=0
  55.       END IF
  56.       GET MOUSE x,y,s             ! Check for mouse press
  57.       IF s>=1 then
  58.          GET POINT x,y            ! Get the mouse press
  59.          LET result=0
  60.          CALL PtInRect(x,y,.12,.295,.7,.8,result)     ! Level 1
  61.          IF result=1 then
  62.             LET skilllevel=8
  63.             LET level=1
  64.             CALL SetStartGameButton(Level)
  65.          END IF
  66.          LET result=0
  67.          CALL PtInRect(x,y,.32,.495,.7,.8,result)     ! Level 2
  68.          IF result=1 then
  69.             LET skilllevel=14
  70.             LET level=2
  71.             CALL SetStartGameButton(Level)
  72.          END IF
  73.          LET result=0
  74.          CALL PtInRect(x,y,.505,.680,.7,.8,result)    ! Level 3
  75.          IF result=1 then
  76.             LET skilllevel=20
  77.             LET level=3
  78.             CALL SetStartGameButton(Level)
  79.          END IF
  80.          LET result=0
  81.          CALL PtInRect(x,y,.705,.880,.7,.8,result)    ! Level 4
  82.          IF result=1 then
  83.             LET skilllevel=31
  84.             LET level=4
  85.             CALL SetStartGameButton(Level)
  86.          END IF
  87.          LET result=0
  88.          CALL PtInRect(x,y,.3,.7,.05,.15,result)
  89.          IF result=1 then
  90.             ! Quit Routine
  91.             SET COLOR "White"
  92.             BOX AREA 0,1,0,1
  93.             SET COLOR "Black"
  94.             BOX LINES 0,1,0,1
  95.             SET COLOR "Blue"
  96.             CALL MacTextSize(24)
  97.             PLOT TEXT, AT .5,.6:"Thank you for"
  98.             PLOT TEXT, AT .5,.4:"Reading MacTutor™"
  99.             STOP
  100.          END IF
  101.          LET result=0
  102.          CALL PtInRect(x,y,.3,.7,.2,.3,result)
  103.          IF result=1 then
  104.             ! Play the Game
  105.             BOX SHOW none$ at 0,0
  106.             LET x=0
  107.             LET y=0
  108.             LET numberofnotes=1
  109.             LET tempo=100
  110.             DO until numberofnotes=skilllevel
  111.                CALL PlaySequence(numberofnotes,tempo,notes())
  112.                FOR i=1 to numberofnotes
  113.                    SET COLOR MIX (0) rnd,rnd,rnd
  114.                    GET POINT x,y
  115.                    CALL buttonpress(x,y,selection)
  116.                    IF selection<>notes(i) then
  117.                       CALL MacSysBeep(500)
  118.                       CALL MacSysBeep(500)
  119.                       CALL MacSysBeep(500)
  120.                       EXIT DO
  121.                    END IF
  122.                NEXT i
  123.                LET numberofnotes=numberofnotes+1
  124.                LET tempo=tempo+i*10
  125.                PAUSE 1
  126.             LOOP
  127.             CALL SetButtons(level)
  128.          END IF
  129.       END IF
  130.    LOOP
  131. LOOP
  132. END
  133.  
  134. SUB SetButtons(GameLevel)         ! Set Game Buttons
  135.     CALL MacTextSize(14)
  136.     SET COLOR "white"
  137.     BOX AREA .3,.7,.05,.15        ! Quit Game Button
  138.     BOX AREA .12,.295,.7,.8       ! Level 1 Button
  139.     BOX AREA .32,.495,.7,.8       ! Level 2 Button
  140.     BOX AREA .505,.680,.7,.8      ! Level 3 Button
  141.     BOX AREA .705,.880,.7,.8      ! Level 4 Button
  142.     SET COLOR "Black"
  143.     BOX LINES .3,.7,.05,.15       ! Quit Game Button
  144.     BOX LINES .12,.295,.7,.8      ! Level 1 Button
  145.     BOX LINES .32,.495,.7,.8      ! Level 2 Button
  146.     BOX LINES .505,.680,.7,.8     ! Level 3 Button
  147.     BOX LINES .705,.880,.7,.8     ! Level 4 Button
  148.     SET COLOR "Red"
  149.     CALL SetStartGameButton(GameLevel)
  150.     PLOT TEXT, AT .5,.11:"Quit Game"
  151.     CALL MacTextSize(12)
  152.     PLOT TEXT, AT .195,.77:"1"
  153.     PLOT TEXT, AT .4,.77:"2"
  154.     PLOT TEXT, AT .575,.77:"3"
  155.     PLOT TEXT, AT .825,.77:"4"
  156. END SUB
  157.  
  158. SUB SetStartGameButton(GameLevel)      ! Set up the Start Game Button
  159.     SET COLOR MIX (0) rnd,rnd,rnd
  160.     CALL MacTextSize(14)
  161.     SET COLOR "White"
  162.     BOX AREA .1,.9,.2,.3          ! Start Game Button
  163.     SET COLOR "Black"
  164.     BOX LINES .1,.9,.2,.3         ! Start Game Button
  165.     SET COLOR "Red"
  166.     PLOT TEXT, AT .5,.26:"Start Game Level " & STR$(Gamelevel)
  167. END SUB
  168.  
  169. SUB SetNone                       ! Display the PICT with colors off
  170.     BOX SHOW None$ at 0,0
  171. END SUB
  172.  
  173. SUB SetRed
  174.     SET COLOR MIX (13) 1,0,0
  175.     SET COLOR 13
  176. END SUB
  177.  
  178. SUB DarkRed
  179.     SET COLOR MIX (13) 0,0,0
  180.     SET COLOR 13
  181. END SUB
  182.  
  183. SUB SetGreen
  184.     SET COLOR MIX (14) 0,1,0
  185.     SET COLOR 14
  186. END SUB
  187.  
  188. SUB DarkGreen
  189.     SET COLOR MIX (14) 0,0,0
  190.     SET COLOR 14
  191. END SUB
  192.  
  193. SUB SetBlue
  194.     SET COLOR MIX (15) 0,0,1
  195.     SET COLOR 15
  196. END SUB
  197.  
  198. SUB DarkBlue
  199.     SET COLOR MIX (15) 0,0,0
  200.     SET COLOR 15
  201. END SUB
  202.  
  203. SUB SetYellow
  204.     SET COLOR MIX (16) .9,1,0
  205.     SET COLOR 16
  206. END SUB
  207.  
  208. SUB DarkYellow
  209.     SET COLOR MIX (16) 0,0,0
  210.     SET COLOR 16
  211. END SUB
  212.  
  213. SUB FlashRed
  214.     SET COLOR MIX (13) 1,0,0
  215.     LET note$="o5 mf ms c"
  216.     PLAY note$
  217.     PAUSE .5
  218.     SET COLOR MIX (13) 0,0,0
  219. END SUB
  220.  
  221. SUB FlashGreen
  222.     SET COLOR MIX (14) 0,1,0
  223.     LET note$="o5 mf ms a"
  224.     PLAY note$
  225.     PAUSE .5
  226.     SET COLOR MIX (14) 0,0,0
  227. END SUB
  228.  
  229. SUB FlashBlue
  230.     SET COLOR MIX (15) 0,0,1
  231.     LET note$="o5 mf ms >a"
  232.     PLAY note$
  233.     PAUSE .5
  234.     SET COLOR MIX (15) 0,0,0
  235. END SUB
  236.  
  237. SUB FlashYellow
  238.     SET COLOR MIX (16) 1,1,0
  239.     LET note$="o5 mf ms e"
  240.     PLAY note$
  241.     PAUSE .5
  242.     SET COLOR MIX (16) 0,0,0
  243. END SUB
  244.  
  245. SUB PtInRect(x,y,left,right,bottom,top,Result)   ! See if point is in Rectangle
  246.     IF x>left and x<right and y>bottom and y<top then
  247.        LET Result=1
  248.     ELSE
  249.        LET Result=0
  250.     END IF
  251. END SUB
  252.  
  253. SUB Buttonpress(x,y,selection)    ! Handle button press
  254.     CALL PtInRect(x,y,0,.5,.5,1,result)
  255.     IF result=1 then LET selectedcolor=13
  256.     CALL PtInRect(x,y,0,.5,0,.5,result)
  257.     IF result=1 then LET selectedcolor=14
  258.     CALL PtInRect(x,y,.5,1,.5,1,result)
  259.     IF result=1 then LET selectedcolor=15
  260.     CALL PtInRect(x,y,.5,1,0,.5,result)
  261.     IF result=1 then LET selectedcolor=16
  262.     SELECT CASE selectedcolor
  263.     CASE 13
  264.          CALL flashred
  265.          LET selection=1
  266.     CASE 14
  267.          CALL flashgreen
  268.          LET selection=2
  269.     CASE 15
  270.          CALL flashblue
  271.          LET selection=3
  272.     CASE 16
  273.          CALL flashyellow
  274.          LET selection=4
  275.     CASE ELSE
  276.          LET selection=0
  277.     END SELECT
  278. END SUB
  279.  
  280. SUB PlaySequence(numberofnotes,tempo,notes())    ! Play the notes
  281.     LET tempo$="t"&str$(tempo)
  282.     PLAY tempo$
  283.     FOR i=1 to numberofnotes
  284.         SET COLOR MIX (0) rnd,rnd,rnd
  285.         IF notes(i)=0 then
  286.            LET note=int(4*rnd)+1
  287.         ELSE
  288.            LET note=notes(i)
  289.         END IF
  290.         SELECT CASE note
  291.         CASE 1
  292.              CALL flashred
  293.         CASE 2
  294.              CALL flashgreen
  295.         CASE 3
  296.              CALL flashblue
  297.         CASE 4
  298.              CALL flashyellow
  299.         END SELECT
  300.         LET notes(i)=note
  301.     NEXT i
  302. END SUB
  303.